<?php
  require_once 'DB.php';
  include_once("./libraries/db.inc.php");
  include_once("./libraries/util.inc.php");
  include_once("./libraries/authentication.inc.php");
  include_once("./queries/prov.inc.php");
  include_once("./libraries/recordset.inc.php");

  session_start();
  sessionAuthenticate("login.php");  

  $dataIndex = "provDAGParentByDate";
  $displayPage = 1;

  // Process the GET variables
  foreach($_GET as $varName => $value) {
    if ($varName == "dP") {
      $displayPage = $value;
    }
    if ($varName == "startDate") {
      $startDate = $value;
      $_SESSION["{$dataIndex}"]["startDate"] = $startDate;
    }
    if ($varName == "endDate") {
      $endDate = $value;
      $_SESSION["{$dataIndex}"]["endDate"] = $endDate;
    }
  }

  $username = $_SESSION["loginUsername"];
  $startDate = $_SESSION["{$dataIndex}"]["startDate"];
  $endDate = $_SESSION["{$dataIndex}"]["endDate"];
  $title = "Find DAG Node by Queue Date";
  $message = "Your DAG Nodes with Queue Date between $startDate and $endDate.<br>Select a Node Name.";

  // Connect to the database
  $connection = DB::connect($dsn, $options);
  if (DB::isError($connection)) {
    trigger_error($connection->getMessage(), E_USER_ERROR);
  }

  // Run the query
  $rs = dagNodeByDate($connection, $startDate, $endDate, $username,
                        $displayPage);
  $connection->disconnect();

  $rs->setLinkParams(2, array("DAGManJobId","DAGNodeName"), array(0,2), "provDAGNodeParentAction.php");

  $rs->printNavigablePage($title, $message, $displayPage, 
                          "./provDAGParentByDate.php");

  cdbFinishPage();
?>
